import router from "./router";
import store from "./store"

/**
 * 白名单
 */
const whiteList = ["/login"]

/**
 * 路由前置守卫
 */
router.beforeEach(async (to, from, next) => {
    if (store.getters.token) {
        if (to.path === "/login") {
            next("/")
        } else {
            if (!store.getters.hasUserInfo) {
                await store.dispatch("user/getUserInfo")
            }
            next()
        }
    } else {
        if (whiteList.indexOf(to.path) > -1) {
            next()
        } else {
            next("/login")
        }
    }
})

